package com.csun.cmny.provider.controller.admin;

import com.csun.cmny.core.annotation.ValidateAnnotation;
import com.csun.cmny.core.support.BaseController;
import com.csun.cmny.provider.model.dto.watch.WatchSafetyRangeDto;
import com.csun.cmny.provider.model.dto.watch.WatchSafetyRangePageQuery;
import com.csun.cmny.provider.model.vo.watch.DmcWatchSafetyRangeVo;
import com.csun.cmny.provider.resolver.CmnyMessageSource;
import com.csun.cmny.provider.service.DmcWatchSafetyRangeService;
import com.csun.cmny.provider.validator.DmcWatchSafetyRangeAddValidator;
import com.csun.cmny.provider.validator.DmcWatchSafetyRangeEditValidator;
import com.csun.cmny.util.wrapper.WrapMapper;
import com.csun.cmny.util.wrapper.Wrapper;
import com.github.pagehelper.PageInfo;
import org.springframework.http.MediaType;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2019-01-27 14:41
 * @Description: the class watch safety range controller
 */
@RestController
@RequestMapping(value = "/watch", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class WatchSafetyRangeController extends BaseController {

    @Resource
    private DmcWatchSafetyRangeService dmcWatchSafetyRangeService;
    @Resource
    private CmnyMessageSource cmnyMessageSource;

    /**
     * 查询孝心手环安全区域列表
     */
    //@LogAnnotation(isSaveRequestData = true, isSaveResponseData = true)
    @RequestMapping(value = "/queryWatchSafetyRangeListWithPage", method = RequestMethod.POST)
    public Wrapper queryWatchSafetyRangeListWithPage(@RequestBody WatchSafetyRangePageQuery watchSafetyRangePageQuery) {

        PageInfo pageInfo = dmcWatchSafetyRangeService.queryWatchSafetyRangeListWithPage(watchSafetyRangePageQuery);

       // return WrapMapper.ok(pageInfo);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),pageInfo);
    }

    /**
     * 添加孝心手环安全区域
     */
    @ValidateAnnotation
   // @LogAnnotation(isSaveRequestData = true, isSaveResponseData = true)
    @RequestMapping(value = "/addWatchSafetyRange", method = RequestMethod.POST)
    public Wrapper addWatchSafetyRange(@Validated(value = {DmcWatchSafetyRangeAddValidator.class})
                                           @RequestBody WatchSafetyRangeDto watchSafetyRangeDto,
                                  BindingResult br) {

        Integer result = dmcWatchSafetyRangeService.addWatchSafetyRange(watchSafetyRangeDto, getLoginAuthDto());

      //  return WrapMapper.ok(result);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),result);
    }

    /**
     * 修改孝心手环安全区域
     */
    @ValidateAnnotation
   // @LogAnnotation(isSaveRequestData = true, isSaveResponseData = true)
    @RequestMapping(value = "/editWatchSafetyRange", method = RequestMethod.POST)
    public Wrapper editWatchSafetyRange(@Validated(value = {DmcWatchSafetyRangeEditValidator.class})
                                            @RequestBody WatchSafetyRangeDto watchSafetyRangeDto,
                                       BindingResult br) {

        Integer result = dmcWatchSafetyRangeService.editWatchSafetyRange(watchSafetyRangeDto, getLoginAuthDto());

       // return WrapMapper.ok(result);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),result);
    }


    /**
     * 删除孝心手环安全区域
     */
   // @LogAnnotation(isSaveRequestData = true, isSaveResponseData = true)
    @RequestMapping(value = "/deleteWatchSafetyRangeById/{id}", method = RequestMethod.POST)
    public Wrapper deleteWatchSafetyRangeById(@PathVariable Long id) {

        Integer result = dmcWatchSafetyRangeService.deleteWatchSafetyRangeById(id);

       // return WrapMapper.ok(result);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),result);
    }


    /**
     * 查询孝心手环安全区域 - 根据安全区域Id
     */
   // @LogAnnotation(isSaveRequestData = true, isSaveResponseData = true)
    @RequestMapping(value = "/getWatchSafetyRangeById/{id}", method = RequestMethod.POST)
    public Wrapper getWatchSafetyRangeById(@PathVariable Long id) {

        DmcWatchSafetyRangeVo dmcWatchSafetyRangeVo = dmcWatchSafetyRangeService.getWatchSafetyRangeById(id);

      //  return WrapMapper.ok(dmcWatchSafetyRangeVo);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),dmcWatchSafetyRangeVo);
    }

}
